package com.bktalk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class TestAcitivity extends Activity {
	Button button1 = null;
	
	EditText add1 = null;
	EditText add2 = null;
	
	Button buttonStart = null;
	Button buttonEnd = null;
	
	Handler handler = new Handler();
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int itemid = item.getItemId();
		if(itemid==0)
		{
			finish();
			System.out.println("点击退出");
		}
		else if(itemid==1)
		{
			System.out.println("点击右边菜单");
		}
		// TODO Auto-generated method stub
		return super.onOptionsItemSelected(item);
	}
	
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		menu.add(0, 0, 0, "退出");
		menu.add(0, 1, 1, "保持");
		return super.onCreateOptionsMenu(menu);
		
	};
	
	Runnable runner = new Runnable()
	{
		@Override
		public void run() {
			// TODO Auto-generated method stub
			handler.postDelayed(runner, 3000);
			System.out.println("post message");
		}
		
	};
	
	OnClickListener clicklistener  = new OnClickListener()
	{
		@Override
		public void onClick(View v) {
			switch(v.getId())
			{
				case R.id.button1:
					Intent intent = new Intent();
					intent.setClass(TestAcitivity.this, SecondActivity.class);		
					intent.putExtra("add1", Integer.valueOf(add1.getText().toString()));
					intent.putExtra("add2", Integer.valueOf(add2.getText().toString()));
					TestAcitivity.this.startActivity(intent);
					break;
				case R.id.buttonStart:
					System.out.println("click buttonstart");
					handler.post(runner);
			    	//new Thread(runner).start();
					break;
				case R.id.buttonEnd:
					System.out.println("click buttonend");
					handler.removeCallbacks(runner);
					break;
				default:
					break;
			}
		}
		
	};
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    	System.out.println("TestAcitivity: onCreate");
    	
    	add1 = (EditText)findViewById(R.id.add1);
    	add2 = (EditText)findViewById(R.id.add2);
    	
        button1 = (Button)this.findViewById(R.id.button1);
    	button1.setOnClickListener(clicklistener);
    	
    	buttonStart = (Button)this.findViewById(R.id.buttonStart);
    	buttonEnd = (Button)this.findViewById(R.id.buttonEnd);
    	
    	buttonStart.setOnClickListener(clicklistener);
    	buttonEnd.setOnClickListener(clicklistener);
    }
    
    public void onStart()
    {
    	System.out.println("TestAcitivity: onStart");
    	super.onStart();
    }
    
    protected void onRestart()
    {
    	System.out.println("TestAcitivity: onRestart");
    	super.onRestart();
    }
    
    protected void onResume()
    {
    	System.out.println("TestAcitivity: onResume");
    	super.onResume();
    }
    
    protected void onPause()
    {
    	System.out.println("TestAcitivity: onPause");
    	super.onPause();
    }
    
    protected void onStop()
    {
    	System.out.println("TestAcitivity: onStop");
    	super.onStop();
    }
    
    protected void onDestroy()
    {
    	System.out.println("TestAcitivity: onDestroy");
    	super.onDestroy();
    }
    
}